﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： UserMessageRepository.cs
// 项目名称：斑马车务
// 创建时间：2019/11/15
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using YouWei.Infrastructure.Entity;

namespace YouWei.Infrastructure.Repository
{
	/// <summary>
	/// 仓储层
	/// </summary>	
	public class UserMessageRepository:BaseRepository<UserMessage>
	{		
    
        #region 构造

        public UserMessageRepository() : base(){}

        public UserMessageRepository(string connectionString) : base(connectionString){}

        public UserMessageRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

        /// <summary>
        /// 获取用户消息数量
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public int GetMessageCount(int userID)
        {
            string sql = "SELECT count(1) FROM UserMessage WITH(NOLOCK) WHERE UserID=@UserID AND Status=1";
            return ExecuteScalar<int>(sql, new { UserID = userID});
        }

        /// <summary>
        /// 更新消息状态
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public bool UpdateMessageStatus(int userID)
        {
            string sql = "UPDATE UserMessage SET Status=2,ViewTime=getdate() WHERE UserID=@UserID AND Status=1";
            return Execute(sql, new { UserID = userID })>0;
        }
    }
}